package com.xu.sso.web.service.convert;

import com.xu.sso.core.enums.StatusEnum;
import com.xu.sso.db.model.base.App;
import com.xu.sso.web.model.request.AddAppRequest;
import com.xu.sso.web.model.request.AppSearchRequest;
import com.xu.sso.web.model.request.ChangeAppRequest;

public class AppConvert {

    public static App convert(AddAppRequest request, String username) {
        App app = new App();
        app.setAppId(request.getAppId());
        app.setAppName(request.getAppName());
        app.setAppPath(request.getAppPath());
        app.setAppType(request.getAppType());
        app.setAuthType(request.getAuthType());
        app.setAppDesc(request.getAppDesc());
        app.setDepartment(request.getDepartment());
        app.setRemark(request.getRemark());
        app.setLeader(username);
        app.setStatus(StatusEnum.Start.getCode());
        return app;
    }

    public static App convert(AppSearchRequest request) {
        App app = new App();
        app.setAppId(request.getAppId());
        app.setAppName(request.getAppName());
        app.setStatus(request.getStatus());
        return app;
    }

    public static App convert(ChangeAppRequest request) {
        App app = new App();
        if (!request.getOldAppId().equals(request.getAppId())) {
            app.setAppId(request.getAppId());
        }
        app.setId(request.getId());
        app.setAppName(request.getAppName());
        app.setAppPath(request.getAppPath());
        app.setAppType(request.getAppType());
        app.setAuthType(request.getAuthType());
        app.setAppDesc(request.getAppDesc());
        app.setDepartment(request.getDepartment());
        app.setRemark(request.getRemark());
        return app;
    }

}
